package com.doge.walknovel.business.home.profile.topup

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.doge.wnpro.R
import com.doge.walknovel.api.model.RechargeProductInfo
import com.doge.walknovel.core.base.adapters.AdapterCallback
import com.doge.walknovel.core.base.adapters.ITEM_CLICKED
import com.doge.wnpro.databinding.CellTopUpBinding
import com.doge.walknovel.utils.getColor
import com.doge.walknovel.utils.load
import com.doge.walknovel.utils.screenWidth

class TopUpViewHolder(
    parent: ViewGroup,
    callback: AdapterCallback,
    private val binding: CellTopUpBinding = CellTopUpBinding.inflate(
        LayoutInflater.from(parent.context), parent, false
    ),
) : RecyclerView.ViewHolder(binding.root) {
    init {
        binding.item.setOnClickListener {
            callback.invoke(ITEM_CLICKED, itemView.tag)
        }
    }

    fun bind(item: RechargeProductInfo) {
        itemView.tag = item

        binding.ad.load(item.promotionUrl, width = 1, height = binding.ad.layoutParams.height, type = 7)
        binding.icon.load(item.productImage, width = screenWidth / 4, height = screenWidth / 4)
        binding.price.text = item.realGooglePrice
        binding.loadingPrice.isVisible = item.realGooglePrice.isNullOrEmpty()
        binding.get.text = item.giveDesc
        binding.content.setBackgroundResource(
            if (item.appSelected == true)
                R.drawable.shape_ff8da5_5_stroke else R.drawable.shape_ebebeb_5_stroke
        )
        binding.coverShadow.setShadowColor(
            getColor(if (item.appSelected == true) "#33ff8da5" else "#0c000000")
        )
    }
}